package com.grts.mall.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.grts.mall.pojo.Product;
import com.grts.mall.pojo.ProductExample;
import com.grts.mall.pojo.vo.ProductSearchConditionVo;
import com.grts.mall.pojo.vo.SerachCondtion;

@Mapper
public interface ProductMapper {
    long countByExample(ProductExample example);

    int deleteByExample(ProductExample example);

    int deleteByPrimaryKey(Long pid);

    int insert(Product record);

    int insertSelective(Product record);

    List<Product> selectByExampleWithBLOBs(ProductExample example);

    List<Product> selectByExample(ProductExample example);

    Product selectByPrimaryKey(Long pid);

    int updateByExampleSelective(@Param("record") Product record, @Param("example") ProductExample example);

    int updateByExampleWithBLOBs(@Param("record") Product record, @Param("example") ProductExample example);

    int updateByExample(@Param("record") Product record, @Param("example") ProductExample example);

    int updateByPrimaryKeySelective(Product record);

    int updateByPrimaryKeyWithBLOBs(Product record);

    int updateByPrimaryKey(Product record);
    
    List<Product> selectPageList(ProductSearchConditionVo vo);
    
    @Select("SELECT pid, title, sell_point, cover, price ,on_sale FROM product ORDER BY pid DESC LIMIT #{num}")
    List<Product> selectNewProducts(@Param("num") Integer num);
    
    @Select("SELECT p.* FROM product p\r\n" + 
    		"ORDER BY (\r\n" + 
    		" SELECT SUM(quantity) FROM order_item oi\r\n" + 
    		" INNER JOIN `order` o ON o.oid = oi.oid\r\n" + 
    		" WHERE oi.pid = p.pid AND TIMESTAMPADD(DAY,7,o.create_time) >= NOW()\r\n" + 
    		")DESC LIMIT #{num}")
    List<Product> selectHotPorduct(@Param("num") Integer num);
    
    long countByKeyword(SerachCondtion vo);
    
    List<Product> selectPageListByKeyWord(SerachCondtion vo);
}

